package query

import (
	"context"

	"server_1.0/api/internal/svc"
	"server_1.0/api/internal/types"
	"server_1.0/service/result/result"
	"server_1.0/util"

	"github.com/zeromicro/go-zero/core/logx"
)

type QueryResultSnoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewQueryResultSnoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryResultSnoLogic {
	return &QueryResultSnoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *QueryResultSnoLogic) QueryResultSno(req *types.ResQuerySnoReq) (resp *types.PostReps, err error) {
	Resp, _ := l.svcCtx.ResultRpc.Query(l.ctx, &result.QueryReq{
		Pno: "",
		Sno: req.Sno,
	})
	code := util.Success
	Msg := "查询成功"
	if Resp.QRs[0].Code != 200 {
		code = util.NoFoundError
		Msg = "无记录"
	}

	return &types.PostReps{
		Code: code,
		Msg:  Msg,
		Data: map[string]interface{}{
			"count":  Resp.Count,
			"res":    Resp.QRs,
			"source": "result by sno",
		},
	}, nil
}
